package com.rem.controller;

import com.rem.configration.SwaggerConfig;
import com.rem.domain.User;
import com.rem.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import java.util.List;

/**
 * @author remembrance
 * @version 1.0
 * @date 2021/9/2 13:34
 */

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserServiceImpl userService;

    @GetMapping("addUser")
    public String addUser(){
        return "addUser";
    }

    @RequestMapping("/showUser")
    public ModelAndView showUser(){
        List<User> users = userService.queryUserList();
        ModelAndView mv = new ModelAndView();
        mv.setViewName("user");
        mv.addObject("users",users);
        return mv;
    }


    @PostMapping("insertUser")
    public String insertUser(User user) {
        userService.insertInto(user);
        return "forward:/showUser";
    }
}
